#include "net.h"

int main()
{
	int fd;
	struct sockaddr_in soc;

	//创建套接字
	if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
	{
		perror("socket");
		exit(1);
	}

	//填充ip和端口
	soc.sin_family = AF_INET;
	soc.sin_port = htons(PORT);
	if(( inet_pton(AF_INET, IP_ADDR, (void*)&soc.sin_addr)) != 1)
	{

		perror("inet_pton");
		exit(1);
	}

	//连接服务器
	if((connect(fd, (struct sockaddr* )&soc, sizeof(soc))) < 0)
	{
		perror("");
		exit(1);
	}
	printf("服务器启动成功\n");

	//写
	int ret;
	char buf[BUFSI];
	while(1)
	{
		bzero(buf, BUFSI);
		if( fgets(buf, BUFSI -1, stdin) == NULL)
		{
			continue;
		}
		do
		{
			ret = write(fd, buf, strlen(buf));
		}while(ret < 0 && errno == EINTR);

	}
	close(fd);

	return 0;
}
























